package com.youlu.campus.web.community.controller;

import com.youlu.campus.common.utils.excel.ExcelUtils;
import com.youlu.campus.entity.VO.req.ImportCertificateUpdateVO;
import com.youlu.campus.service.data.CertificateDataService;
import com.youlu.campus.web.order.service.OrderService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
public class CertificateDataController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private CertificateDataService certificateDataService;

    @GetMapping("/public/order/certificate")
    public void orderCertificate(@RequestParam("activityId") String activityId,@RequestParam("startTime") String startTime, @RequestParam("endTime")String endTime){
        orderService.handleOrderCertificate(activityId,startTime,endTime);
    }
    @GetMapping("/public/order/address")
    public void orderUpdateAddress(){
        orderService.orderAddressUpdate();
    }

    /**
     * 证书编号更新
     * @param file
     * @param activityId
     * @return
     */
    @PostMapping("/public/certificateNo/update")
    public QResult importCertificate(@RequestParam("file") MultipartFile file,
                                     @RequestParam("activityId") String activityId){
        ExcelUtils<ImportCertificateUpdateVO> excelUtil = new ExcelUtils();
        List<ImportCertificateUpdateVO> excelDataList = excelUtil.readExcel(file, ImportCertificateUpdateVO.class);
        if (CollectionUtils.isEmpty(excelDataList)) {
            return QResult.fail("导入文件错误");
        }
        certificateDataService.certificateNoUpdate(activityId,excelDataList);
        return QResult.success(null);
    }


}
